//
//  Monster.m
//  Cocos2DSimpleGame
//
//  Created by admin on 3/14/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "Monster.h"

@implementation Monster

#define kRandomX        1
#define kRandomY        200

@synthesize hp = _hp;
@synthesize score = _score;
@synthesize minDuration = _minDuration;
@synthesize maxDuration = _maxDuration;
@synthesize shipLasers = _shipLasers;
@synthesize batchNode =_batchNode;

- (id)init{

    if ((self = [super init])) {
        _hp = 3;
        _score = 3;
        _minDuration = 3;
        _maxDuration = 5;
        _shipLasers = [[CCArray alloc] init];
    }
    
    return self;
}
- (void)setInvisible:(CCNode *)node {
    node.visible = NO;
    [_shipLasers removeObject:node];
}
-(void)shoot{
    CCSprite *shipLaser = [CCSprite spriteWithSpriteFrameName:@"laserbeam_red.png"];
    
    shipLaser.position = ccpAdd(self.position, ccp(shipLaser.contentSize.width/2, 0));
    shipLaser.visible = YES;
    [shipLaser stopAllActions];
    
    [shipLaser runAction:[CCSequence actions:
                          [CCMoveBy actionWithDuration:0.5 position:ccp(- self.position.x, 0)],
                          [CCCallFuncN actionWithTarget:self selector:@selector(setInvisible:)],
                          nil]];
    [_shipLasers addObject:shipLaser];
    [self.batchNode addChild:shipLaser];
}
-(void)moveAroundPosition:(CGPoint)goal{
    CGSize winSize = [CCDirector sharedDirector].winSize;
    CGPoint xy = CGPointMake(self.position.x + arc4random() % kRandomX ,  goal.y + (arc4random() % kRandomY) - kRandomY / 2);
    if (xy.y < 0 ) {
        xy.y = 0;
    }else if (xy.y > winSize.height)
    {
        xy.y = winSize.height;
    }
    [self runAction: [CCMoveTo actionWithDuration:0.5 position:xy]];
    
}

- (void)dealloc
{
    [super dealloc];
}
@end

